package com.Xht.www.servlet;

//后端响应下单时同步销量的请求

import com.Xht.www.dao.MerchantInfoDAO;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/SyncSalesVolumeServlet")
public class SyncSalesVolumeServlet extends HttpServlet {
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        MerchantInfoDAO merchantDAO = new MerchantInfoDAO();
        int updatedCount = merchantDAO.syncSalesVolumeFromSalesTable();

        // 设置响应内容类型
        response.setContentType("text/plain");
        response.setCharacterEncoding("UTF-8");

        if (updatedCount >= 0) {
            response.getWriter().write("成功同步 " + updatedCount + " 条商家销量数据");
        } else {
            response.getWriter().write("同步销量数据失败");
        }
    }
}
